package meta.api.web.account.businessinfo;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import meta.api.web.common.util.ApiConst;
import meta.common.util.StrUtil;

/**
 * 用户
 */
public class UserInfo implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @JsonProperty
    private String id;

    /**
     * 账户
     */
    @JsonProperty
    private String account;

    /**
     * 头像URL
     */
    @JsonProperty
    private String avatarUrl;

    /**
     * 用户名
     */
    @JsonProperty
    private String username;

    /**
     * 密码
     */
    @JsonProperty
    private String password;

    /**
     * 电话
     */
    @JsonProperty
    private String phone;

    /**
     * 邮箱
     */
    @JsonProperty
    private String email;

    /**
     * 角色名列表
     */
    @JsonProperty(value = "roles")
    private List<String> roleNmList;

    /**
     * 角色权限Code值列表
     */
    @JsonIgnore
    private List<Long> roleAuthCdList;

    /**
     * 团队
     */
    @JsonProperty
    private List<TeamInfo> teams;

    /**
     * 部门
     */
    @JsonProperty
    private OrganizationInfo department;

    /**
     * 公司
     */
    @JsonProperty
    private OrganizationInfo company;

    /**
     * 企业
     */
    @JsonProperty
    private CorporationInfo corporation;

    /**
     * 邀请码
     */
    @JsonProperty
    private String inviteCode;

    /**
     * 关联微信账号
     */
    @JsonProperty
    private String wechat;

    /**
     * 关联GitHub账号
     */
    @JsonProperty
    private String github;

    /**
     * 关联新浪账号
     */
    @JsonProperty
    private String sina;

    /**
     * 会员有效期截止时间
     */
    @JsonProperty
    private Integer vip;

    /**
     * 自动登录标识
     */
    @JsonProperty
    private Boolean remember;

    /**
     * 验证码(短信/邮件)/旧密码
     */
    @JsonProperty
    private String code;

    /**
     * 身份认证token
     */
    @JsonProperty
    private String token;

    public void rebuildByAccount() {
        if (StrUtil.isEmpty(this.account)) {
            return;
        }
        if (ApiConst.PATTERN_PHONE.matcher(this.account).matches()) {
            this.username = this.account;
            this.phone = this.account;
        } else if (ApiConst.PATTERN_EMAIL.matcher(this.account).matches()) {
            this.username = this.account.substring(0, this.account.lastIndexOf("@"));
            this.email = this.account;
        } else {
            this.username = this.account;
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<String> getRoleNmList() {
        return roleNmList;
    }

    public void setRoleNmList(List<String> roleNmList) {
        this.roleNmList = roleNmList;
    }

    public List<Long> getRoleAuthCdList() {
        return roleAuthCdList;
    }

    public void setRoleAuthCdList(List<Long> roleAuthCdList) {
        this.roleAuthCdList = roleAuthCdList;
    }

    public List<TeamInfo> getTeams() {
        return teams;
    }

    public void setTeams(List<TeamInfo> teams) {
        this.teams = teams;
    }

    public OrganizationInfo getDepartment() {
        return department;
    }

    public void setDepartment(OrganizationInfo department) {
        this.department = department;
    }

    public OrganizationInfo getCompany() {
        return company;
    }

    public void setCompany(OrganizationInfo company) {
        this.company = company;
    }

    public CorporationInfo getCorporation() {
        return corporation;
    }

    public void setCorporation(CorporationInfo corporation) {
        this.corporation = corporation;
    }

    public String getInviteCode() {
        return inviteCode;
    }

    public void setInviteCode(String inviteCode) {
        this.inviteCode = inviteCode;
    }

    public String getWechat() {
        return wechat;
    }

    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    public String getGithub() {
        return github;
    }

    public void setGithub(String github) {
        this.github = github;
    }

    public String getSina() {
        return sina;
    }

    public void setSina(String sina) {
        this.sina = sina;
    }

    public Integer getVip() {
        return vip;
    }

    public void setVip(Integer vip) {
        this.vip = vip;
    }

    public Boolean getRemember() {
        return remember;
    }

    public void setRemember(Boolean remember) {
        this.remember = remember;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }
}
